package dex.studio.compose.news.ui.tools

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dex.studio.compose.news.ui.data.bean.NewsBean
import kotlinx.coroutines.channels.Channel
import java.util.concurrent.ArrayBlockingQueue

enum class ScreenName {
    ListPage, DetailPage
}

open class Screen(val s: ScreenName) {
    object ListPage : Screen(ScreenName.ListPage)

    //Constructors are not allowed for objects
    data class Detail(val newsBean: NewsBean) : Screen(ScreenName.DetailPage)
//    data class Article(val postId: String) : Screen(ARTICLE)
}

object NewsNavigation {
    val currentScreen = mutableStateOf<Screen>(Screen.ListPage)
    val navList = mutableListOf(currentScreen.value)

    /**
     * 跳转到某个页面
     */
    fun to(screenName: Screen) {
        currentScreen.value = screenName
        navList.add(screenName)
    }
    /**
     * 返回到上一页
     */
    fun backAndReturnsIsLastPage(): Boolean {
        return if (navList.last() is Screen.ListPage) {
            //当前是最后一页了，返回true
            true
        } else {
            val removedLastScreen = navList.removeLast()
            currentScreen.value = navList.last()
            false
        }
    }
}